var relationship_data=[
								{text:'并且',value:'and',selected:true},
								{text:'或者',value:'or'}
			          ];
		 
		var Operator_data= [
		               		{text:'等于',value:'eq',selected:true},
		               		{text:'小于',value:'Less'},
		               		{text:'大于',value:'Greater'},
		               		{text:'大于等于',value:'GreaterEq'},
		               		{text:'小于等于',value:'LessEq'},
		               		{text:'不等于',value:'notEq'},
		               		{text:'包含',value:'Contain'},
		               		{text:'左包含',value:'likeLeft'},
		               		{text:'右包含',value:'likeRight'}
		               		//,{text:'集合',value:'in'}
		               		];

		
		
   		//增加查询条件
		function add_searchbox_filter(searchbox_id){			
			var cvalue=$("#"+searchbox_id.replace("_grid","")+"_fieldlist").combobox('getValue');								
			if(null==cvalue||cvalue==""){
				$.messager.alert('提示','请选择字段!','error'); 
				return;
			}
			$('#'+searchbox_id).datagrid('insertRow',{	
				row: {
				filterfield:cvalue,
				relationship:'and',
				Operator:'eq',
				value:''
				}
			});
						
		}
	//删除查询条件
		function del_searchbox_filter(searchbox_id){
			var selectrow=$('#'+searchbox_id).datagrid('getSelected');
			if(selectrow==null){
				alert("请选择数据!");
				return;
			}
			var current_selected_rowindex=$('#'+searchbox_id).datagrid('getRowIndex',selectrow);
			$('#'+searchbox_id).datagrid('deleteRow',current_selected_rowindex);
			
		}

	//改变选中的字段
	function select_field_change(searchbox_id,rowdata){
		var data =eval('('+rowdata.editor+')');
		//alert(data.type);
		}

	//查询框单击事件
	//var lastIndex=-1;
	function searchbox_row_onclick(grid_id,rowIndex,rowData){	
		var parent_grid_id=grid_id.replace("_grid","");			
		var fields = $('#'+eval($("#"+parent_grid_id).attr("easytagdata"))).datagrid('options').columns;
		var frozen_field=$('#'+eval($("#"+parent_grid_id).attr("easytagdata"))).datagrid('options').frozenColumns;
		var field_data=[];
		//得到普通列
		for(var i=0;i<fields.length;i++){
			for(var j=0;j<fields[i].length;j++){
				if(!fields[i][j].checkbox
					&& "undefined" != typeof fields[i][j].editor
				){
				field_data.push(fields[i][j]);
				}
				
			}
		}
		//得到冻结列
		for(var i=0;i<frozen_field.length;i++){
			for(var j=0;j<frozen_field[i].length;j++){
				if(!frozen_field[i][j].checkbox && "undefined" != typeof frozen_field[i][j].editor){
				field_data.push(frozen_field[i][j]);			
				}
				
			}
		}
		//alert(field_data.length+":"+rowData.filterfield+":"+$(parent_grid_id+"_data"));
		var param_exists=false;//是否为普通列配置字段   false 为 searchboxparamtag 配置的参数
		for(var i=0;i<field_data.length;i++){
			var obj=field_data[i];
			if(obj.field==rowData.filterfield){				
				var ed = $('#'+grid_id).datagrid('getColumnOption','value');
				ed.editor=obj.editor;	
				//alert(obj.editor);
				$('#'+grid_id).datagrid('beginEdit', rowIndex);		
				param_exists=true;
				break;
			}
			
		}
		
		//如果是searchboxparamtag 配置的参数
		if (param_exists==false) {
			var searchboxParamData=eval(parent_grid_id+"_data");
			for(var i =0;i<searchboxParamData.length;i++){
				if(searchboxParamData[i].field==rowData.filterfield){
					var ed = $('#'+grid_id).datagrid('getColumnOption','value');
					ed.editor=eval('('+searchboxParamData[i].editor+')');
					$('#'+grid_id).datagrid('beginEdit', rowIndex);						
					break;
				}
			}
		}
		
		
	}
	
	
	/**
	 * 打开查询框
	 * @param grid_id
	 * @return
	 */
	function open_searchbox(searchbox_id){
		$('#'+searchbox_id+"_searchbox").dialog('open');  // open a window 
	}	
	
	function queryColumns(searchbox_id){
		var target_data=eval($('#'+searchbox_id+"_searchbox").attr("easytagdata"));		
		var fields = $('#'+target_data).datagrid('options').columns;
		var field_data=[];
		for(var i=0;i<fields.length;i++){
			for(var j=0;j<fields[i].length;j++){
				if(!fields[i][j].checkbox
					&& "undefined" != typeof fields[i][j].editor
				){
				field_data.push(fields[i][j]);				
				}
				
			}
		}
		return field_data;
	}
	
	
	
	
	/**
	 * 得到当前条件列表
	 * @param searchbox_grid_id
	 * @return
	 */
	function getCurrentFilter(searchbox_grid_id){			
		var data = null;
		data=$("#"+searchbox_grid_id).datagrid('getRows');
		var str =Serialize(data);
		return str;
	}
	
	/**
	 * 验证查询框里的条件是否全都合法
	 * @param searchbox_id
	 * @return
	 */
	function validation_current_rows(searchbox_id){		
		var okay=true;
		var data=$("#"+searchbox_id+"_grid").datagrid('getRows');			
		for(var i=0;i<data.length;i++){
			if($("#"+searchbox_id+"_grid").datagrid('validateRow',i)==false){
				okay=false;
			}else{
				$("#"+searchbox_id+"_grid").datagrid('endEdit',i);
				var rows = $("#"+searchbox_id+"_grid").datagrid('getRows');    // get current page rows
				var row = rows[i];    // your row data
				if(row.relationship==""||row.Operator==""||row.value==""){
					okay=false;
				}			
				
			}
		}
		return okay;
		
	}
	
	/**
	 * 得到查询盒子里的查询参数信息
	 * @param searchbox_id  查询框的ID
	 * @return
	 */
	function getSearchBoxFilter(searchbox_id){
		if(validation_current_rows(searchbox_id+'_searchbox')==false){
			$.messager.alert('提示','请处理好错误之后再进行查询!','error'); 
			return;
		}
		var filter_str=getCurrentFilter(searchbox_id+'_searchbox_grid');
		return filter_str;
	}
	
	
	/**
	 * 执行查询
	 * @param searchbox_id
	 * @return
	 */
	function query_for_grid(searchbox_id){
		//自定义查询参数
		var searchbox_param_data=eval(searchbox_id+"_data");
		//得到父容 器
		var target_obj=eval($('#'+searchbox_id).attr("easytagdata"));
		//得到grid查询参数信息
		var args_metadata=getQueryArgsInfo(target_obj);
		//添加自定义参数
		for(var i=0;i<searchbox_param_data.length;i++){
			var temp = new Object();
			//alert(searchbox_param_data[i].field+":"+eval('('+searchbox_param_data[i].editor+')').type);
			temp.filed=searchbox_param_data[i].field;
			temp.editor=eval('('+searchbox_param_data[i].editor+')').type;
			args_metadata.push(temp);
		}
		
		//判断是否有错误情况
		if(validation_current_rows(searchbox_id)==false){
			$.messager.alert('提示','请处理好错误之后再进行查询!','error'); 
			return;
		}
		//得到当前条件
		var filter_str=getCurrentFilter(searchbox_id+"_grid");
		//重新加载列表		
		var current_args=$('#'+target_obj).datagrid('options').queryParams;
		current_args.filter=encodeURI(filter_str);
		current_args.meta=encodeURI(Serialize(args_metadata));
		current_args.c="q";
		$('#'+target_obj).datagrid('reload',current_args);
		$('#'+searchbox_id).dialog('close');
	}